package com.sunda.spmswms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.sunda.spmswms.entity.*;
import com.sunda.spmswms.mapper.*;
import com.sunda.spmswms.service.IDocumentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.print.Doc;
import java.util.List;

@Service
public class DocumentTypeImpl implements IDocumentType {

    @Autowired
    WhsOutMapper whsOutMapper;
    @Autowired
    InventoryCheckMapper inventoryCheckMapper;
    @Autowired
    ShelfOnTaskMapper shelfOnTaskMapper;
    @Autowired
    WhsMoveMapper whsMoveMapper;
    @Autowired
    WithdrawTaskMapper withdrawTaskMapper;
//    SAPDN,SAP DN
//    NS-OUT-HOUSE,南沙出库
//    NS-INVCHK,南沙盘点
//    PACK-LIST,装箱单号
//    SHELF-ON-OFF,南沙上下架
//    NS-WHS-MOVE,南沙移仓
//    NS-WITHDRAW,南沙移动冲销
//    NS-EXCEPTION,南沙异常出入库
    @Override
    public DocumentType getUuidByDocType(String documentType, String documentSpmsId) {
        if(StringUtils.isEmpty(documentSpmsId) || StringUtils.isEmpty(documentType)){
            return null;
        }
        DocumentType document=new DocumentType();
        document.setDocumentType(documentType);
        document.setDocumentSpmsId(documentSpmsId);
        switch (documentType){
            case "NS-OUT-HOUSE":
                WhsOut whsOut=whsOutMapper.selectOne(new QueryWrapper<WhsOut>().eq("WHS_OUT_NO",documentSpmsId));
                if(null!=whsOut){
                    document.setDocumentUuid(whsOut.getUuid());
                }
                return document;
            case "INVCHK":
                InventoryCheck inventoryCheck=inventoryCheckMapper.selectOne(new QueryWrapper<InventoryCheck>().eq("INVENTORY_CHECK_ID",documentSpmsId));
                if(null!=inventoryCheck){
                    document.setDocumentUuid(inventoryCheck.getUuid());
                }
                return document;
            case "SHELF-ON-OFF":
                ShelfOnTask shelfOnTask=shelfOnTaskMapper.selectOne(new QueryWrapper<ShelfOnTask>().eq("TASK_ID",documentSpmsId));
                if(null!=shelfOnTask){
                    document.setDocumentUuid(shelfOnTask.getUuid());
                }
                return document;
            case "NS-WHS-MOVE":
                WhsMove whsMove=whsMoveMapper.selectOne(new QueryWrapper<WhsMove>().eq("WHS_MOVE_NO",documentSpmsId));
                if(null!=whsMove){
                    document.setDocumentUuid(whsMove.getWhsMoveUuid());
                }
                return document;
            case "NS-WITHDRAW":
                WithdrawTask withdrawTask=withdrawTaskMapper.selectOne(new QueryWrapper<WithdrawTask>().eq("TASK_ID",documentSpmsId));
                if(null!=withdrawTask){
                    document.setDocumentUuid(withdrawTask.getUuid());
                }
                return document;
            case "NS-EXCEPTION":
               // TO DO:

                return document;
            default:

                return document;
        }
    }

    @Override
    public DocumentType getSpmsIdByDocUuid(String documentType, String docUuid) {
        if(StringUtils.isEmpty(docUuid) || StringUtils.isEmpty(documentType)){
            return null;
        }
        DocumentType document=new DocumentType();
        document.setDocumentType(documentType);
        document.setDocumentUuid(docUuid);
        switch (documentType){
            case "NS-OUT-HOUSE":
                WhsOut whsOut=whsOutMapper.selectOne(new QueryWrapper<WhsOut>().eq("UUID",docUuid));
                if(null!=whsOut){
                    document.setDocumentSpmsId(whsOut.getWhsOutNo());
                }
                return document;
            case "INVCHK":
                InventoryCheck inventoryCheck=inventoryCheckMapper.selectOne(new QueryWrapper<InventoryCheck>().eq("UUID",docUuid));
                if(null!=inventoryCheck){
                    document.setDocumentSpmsId(inventoryCheck.getInventoryCheckId());
                }
                return document;
            case "SHELF-ON-OFF":
                ShelfOnTask shelfOnTask=shelfOnTaskMapper.selectOne(new QueryWrapper<ShelfOnTask>().eq("UUID",docUuid));
                if(null!=shelfOnTask){
                    document.setDocumentSpmsId(shelfOnTask.getTaskId());
                }
                return document;
            case "NS-WHS-MOVE":
                WhsMove whsMove=whsMoveMapper.selectOne(new QueryWrapper<WhsMove>().eq("WHS_MOVE_UUID",docUuid));
                if(null!=whsMove){
                    document.setDocumentSpmsId(whsMove.getWhsMoveNo());
                }
                return document;
            case "NS-WITHDRAW":
                WithdrawTask withdrawTask=withdrawTaskMapper.selectOne(new QueryWrapper<WithdrawTask>().eq("UUID",docUuid));
                if(null!=withdrawTask){
                    document.setDocumentSpmsId(withdrawTask.getTaskId());
                }
                return document;
            case "NS-EXCEPTION":
                // TO DO:
                document.setDocumentSpmsId(docUuid);
                return document;
            default:
                document.setDocumentSpmsId(docUuid);
                return document;
        }
    }
}
